package com.bigShen.pattern.strategy.pay;

import com.bigShen.pattern.strategy.pay.fact.PayFactType;
import com.bigShen.pattern.strategy.pay.fact.PayFactory;

/**
 * @author: lei.shen
 * @date: 2018/10/5
 */
public class Order {

    private String uid;

    private String orderId;

    private double amount;

    public Order(String uid, String orderId, double amount) {
        this.uid = uid;
        this.orderId = orderId;
        this.amount = amount;
    }

    public PayState payOld(PayMent payMent) {
        return payMent.pay(orderId, amount);
    }


    /**
     * 完美支付方案，传一个枚举类型完成支付
     * @param payType
     * @return
     */
    public PayState pay(PayType payType) {
        return  payType.get().pay(orderId, amount);
    }

    /**
     * 工厂模式, 抽象方法直接返回的是结果,耦合度太高
     * @return
     */
    public PayState payByFactory(PayFactType payFactType) {

        if (payFactType.equals(PayFactType.ALI_PAY)) {
            return new PayFactory().payByALi(orderId, amount);
        } else if (payFactType.equals(PayFactType.JD_PAY)) {
            return new PayFactory().payByJD(orderId, amount);
        } else if (payFactType.equals(PayFactType.WECHAT_PAY)) {
            return new PayFactory().payByWeChat(orderId, amount);
        }
        return null;
    }

}
